<template>
	<view>
		<term-select :vm="termSelectVM" @selectChange="selectChange"></term-select>
		<menuBox :menuInfo = "menuInfo"></menuBox>
	</view>
</template>

<script>
	import menuBox from "@/wxcomponents/commonLayout/menu";
	import termSelect from '@/wxcomponents/termSelect/index.vue'
	import achievementMixins from './achievementMixins.js';
	import userMixins from '@/libs/userMixins.js'
	export default {
		mixins: [achievementMixins, userMixins],
		components: {
			termSelect,
			menuBox
		},
		data() {
			return {
				selectItem: '',
				menuInfo: {
					base:{
						menuProp:[
							"name"
						]
					},
					list:[]
				}
			}
		},
		methods: {
			selectChange(selectItem) {
				this.selectItem = selectItem;
				this.fetchCourseList();
			},
			async fetchCourseList() {
				let self = this;
				let caseMap = [
					{
						condition() {	// 教师
							return self.calMenuShow('普通老师身份');
						},
						async func() {
							let params = {
								termId: self.selectItem.id
							}
							let resp = await self.$http.post({
								url: '/edu/schoolReport/teacher/weChat/pageList',
								data: params
							});
							let list = resp.result.records.map(item => {
								item.name = item.courseName;
								item.url = `/modules/achievement/chooseClass?courseCode=${item.courseCode}`
								return item;
							})
							self.menuInfo.list = list;
						}
					},
					{
						condition() {	// 班主任
							return self.calMenuShow('班主任身份');
						},
						async func() {
							let resp = await self.$http.get({
								url: `/edu/wechat/studentScore/listCourseByTerm/${self.selectItem.id}`,
								data: {}
							});
							let list = resp.result.map(item => {
								let paramsStr = JSON.stringify({
									termId: self.selectItem.id,
									courseCode: item.courseCode,
									classCode: item.classCode,
									className: item.className
								}) 
								item.name = item.courseName;
								item.url = `/modules/achievement/classAchievement?paramsStr=${paramsStr}`
	
								return item;
							})
							self.menuInfo.list = list;
						}
					},
				]
				let findOne = caseMap.filter(item => {
					return item.condition()
				})[0]
				if (!findOne) {
					alert(`fetchCourseList方法出错`)
				}
				findOne.func();
			}
		},
		mounted() {
			this.fetchTerm();
		}
	}
</script>

<style lang="scss" scoped>
	
</style>
